﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region usings

using System;
using System.Collections;
using System.Collections.Generic;
using InterLinq.Base;
using InterLinq.Objects;
using Sebarf.Diagnostics.Interfaces;
using Sebarf.Server;
using Shared;
using Shared.DataObjects;

#endregion

namespace Tutorial {
	internal class Program {
		[STAThread]
		private static void Main() {
			//our sample data
			var persons = new[] {
			                    	new Person {Name = "Person A"}, new Person {Name = "Person B"}, new Person {Name = "Person C"},
			                    	new Person {Name = "Pascal Hauser"}
			                    };
			var cars = new[] {
			                 	new Car {Name = "Audi", OwnedByPerson = "Person A"},
			                 	new Car {Name = "Ferrari", OwnedByPerson = "Person B"},
			                 	new Car {Name = "Lotus Evora", OwnedByPerson = "Pascal Hauser"}
			                 };

			//create and fill a container (which implements IObjectSource)
			var dataContainer = new Dictionary<Type, IList> { { typeof(Person), new List<Person>(persons) }, { typeof(Car), new List<Car>(cars) } };

			//create a object query handler based on our data container
			var queryHandler = new ObjectQueryHandler(new ObjectBasedDataSource(dataContainer));

			//create the server
			IServer server = InterLinqServer.GetSebarfServerForInterLinq(queryHandler, queryHandler,
																		  "RequestHandlerConfiguration.Server.Internal.xml",
																		  "RequestHandlerConfiguration.Server.Application.xml",
																		  "net.tcp://localhost:9876/InterLinqService");

			Logger.WriteInformation("Starting server");
			server.Start();
			Logger.WriteInformation("Server has been started. Is waiting for requests");

			// show close dialog
			new CloseDialog("Server").ShowDialog();
		}
	}
}